package avicit.bdp.dgs.qa.rest;

import avicit.bdp.dgs.qa.dto.WorkOrderDTO;
import avicit.bdp.dgs.qa.dto.WorkOrderHistoryDTO;
import avicit.bdp.dgs.qa.service.WorkOrderService;
import avicit.platform6.core.rest.msg.QueryRespBean;
import avicit.platform6.core.rest.msg.ResponseMsg;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * @金航数码科技有限责任公司
 * @作者：developer
 * @邮箱：developer@avic-digital.com
 * @创建时间： 2023-05-29
 * @类说明：WorkOrderRest
 * @修改记录：
 * @注意事项：
 * @主要功能：工单管理Rest接口
 */
@RestController
@Api(tags = "qa", description = "工单管理Rest接口")
@RequestMapping("/api/bdp/dgs/qa/workOrder")
public class WorkOrderRest {
    @Autowired
    private WorkOrderService workOrderService;

    /**
     * 新增工单
     * @param workOrderDTO
     * @return
     */
    @PostMapping("/add")
    @ApiOperation(value = "新增工单")
    public ResponseMsg<String> addWorkOrder(@RequestBody WorkOrderDTO workOrderDTO) {
        ResponseMsg<String> responseMsg = new ResponseMsg<>();

        responseMsg.setResponseBody(this.workOrderService.addWorkOrder(workOrderDTO));

        return responseMsg;
    }

    /**
     * 删除/批量删除工单，多个id使用英文逗号隔开
     * @param id
     * @return
     */
    @DeleteMapping("/delete")
    @ApiOperation(value = "删除/批量删除工单，多个id使用英文逗号隔开")
    public ResponseMsg<Integer> deleteWorkOrder(@ApiParam(value = "id", name = "id") @RequestParam String id) {
        ResponseMsg<Integer> responseMsg = new ResponseMsg<>();

        responseMsg.setResponseBody(this.workOrderService.deleteWorkOrder(id));

        return responseMsg;
    }

    /**
     * 修改工单
     * @param workOrderDTO
     * @return
     */
    @PostMapping("/update")
    @ApiOperation(value = "修改工单")
    public ResponseMsg<Boolean> updateWorkOrder(@RequestBody WorkOrderDTO workOrderDTO) {
        ResponseMsg<Boolean> responseMsg = new ResponseMsg<>();

        responseMsg.setResponseBody(this.workOrderService.updateWorkOrder(workOrderDTO));

        return responseMsg;
    }

    /**
     * 查询工单基本信息
     * @param id 工单ID
     * @return
     */
    @GetMapping("/info")
    @ApiOperation(value = "查询工单基本信息")
    public ResponseMsg<WorkOrderDTO> getWorkOrderInfo(@ApiParam(value = "id", name = "id") @RequestParam String id) {
        ResponseMsg<WorkOrderDTO> responseMsg = new ResponseMsg<>();

        responseMsg.setResponseBody(this.workOrderService.getWorkOrderInfo(id));

        return responseMsg;
    }

    /**
     * 查询工单详情
     * @param id 工单ID
     * @return
     */
    @GetMapping("/detail")
    @ApiOperation(value = "查询工单详情")
    public ResponseMsg<Map<String, Object>> getWorkOrderDetail(@ApiParam(value = "id", name = "id") @RequestParam String id) {
        ResponseMsg<Map<String, Object>> responseMsg = new ResponseMsg<>();

        responseMsg.setResponseBody(this.workOrderService.getWorkOrderDetail(id));

        return responseMsg;
    }

    /**
     * 查询工单进度
     * @param id 工单ID
     * @return
     */
    @GetMapping("/progress")
    @ApiOperation(value = "查询工单进度")
    public ResponseMsg<List<WorkOrderHistoryDTO>> getWorkOrderProgress(@ApiParam(value = "id", name = "id") @RequestParam String id) {
        ResponseMsg<List<WorkOrderHistoryDTO>> responseMsg = new ResponseMsg<>();

        responseMsg.setResponseBody(this.workOrderService.getWorkOrderProgress(id));

        return responseMsg;
    }

    /**
     * 分页查询工单
     * 注意：
     *  1、自己创建的工单；
     *  2、登录用户和当前处理人一致，可以查看工单并进行处理；
     * @param keyWords
     * @param pageNo
     * @param pageSize
     * @return
     */
    @GetMapping("/query")
    @ApiOperation(value = "分页查询工单")
    public ResponseMsg<QueryRespBean<WorkOrderDTO>> queryWorkOrder(
            @ApiParam(value = "查询关键字", name = "keyWords") @RequestParam(required = false) String keyWords,
            @ApiParam(value = "当前页", name = "pageNo") @RequestParam(defaultValue = "1", required = false) Integer pageNo,
            @ApiParam(value = "每页大小", name = "pageSize") @RequestParam(defaultValue = "10", required = false) Integer pageSize) {
        ResponseMsg<QueryRespBean<WorkOrderDTO>> responseMsg = new ResponseMsg<>();

        responseMsg.setResponseBody(this.workOrderService.queryWorkOrder(keyWords, pageNo,pageSize));

        return responseMsg;
    }

    /**
     * 流转工单
     * @param workOrderDTO
     * @return
     */
    @PostMapping("/flow")
    @ApiOperation(value = "流转工单")
    public ResponseMsg<String> flowWorkOrder(@RequestBody WorkOrderDTO workOrderDTO) {
        ResponseMsg<String> responseMsg = new ResponseMsg<>();

        responseMsg.setResponseBody(this.workOrderService.flowWorkOrder(workOrderDTO));

        return responseMsg;
    }

    /**
     * 验证工单
     * @param workOrderDTO
     * @return
     */
    @PostMapping("/verify")
    @ApiOperation(value = "验证工单")
    public ResponseMsg<String> verifyWorkOrder(@RequestBody WorkOrderDTO workOrderDTO) {
        ResponseMsg<String> responseMsg = new ResponseMsg<>();

        responseMsg.setResponseBody(this.workOrderService.verifyWorkOrder(workOrderDTO));

        return responseMsg;
    }

    /**
     * 忽略验证工单（已解决）
     * @param workOrderDTO
     * @return
     */
    @PostMapping("/ingore")
    @ApiOperation(value = "忽略验证工单")
    public ResponseMsg<String> ingoreVerifyWorkOrder(@RequestBody WorkOrderDTO workOrderDTO) {
        ResponseMsg<String> responseMsg = new ResponseMsg<>();

        responseMsg.setResponseBody(this.workOrderService.ingoreVerifyWorkOrder(workOrderDTO));

        return responseMsg;
    }

    /**
     * 模拟向redis推送消息
     * @param workOrderDTO
     * @return
     */
    @PostMapping("/mock")
    @ApiOperation(value = "模拟向redis推送消息")
    @SuppressWarnings("测试用，待删除。")
    public ResponseMsg mockData(@RequestBody WorkOrderDTO workOrderDTO) {
        ResponseMsg responseMsg = new ResponseMsg();

        this.workOrderService.mockAddRedisData(workOrderDTO);

        return responseMsg;
    }
}
